﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AgileSaude.Data.Repository
{
    public class servicoRepository : IservicoRepository
    {
        agilesaudeEntities entity;

        public servicoRepository()
        {
            entity = agilesaudeContext.getInstance();
        }

        public IQueryable<servico> Getservicos()
        {
            return agilesaudeContext.getInstance().servico;
        }
        
        public IList<servico> GetAll()
        {
            return agilesaudeContext.getInstance().servico.ToList();
        }

        public servico getservico(int pservicoId)
        {
            return entity.servico.SingleOrDefault(a => a.idServico == pservicoId);
        }

        public void Delete(servico pservico)
        {
            try
            {
                entity.servico.DeleteObject(pservico);
                entity.SaveChanges();
            }
            catch (Exception ex)
            {
                agilesaudeContext.removeInstance();
                throw ex;
            }
        }

        public void Add(servico pservico)
        {
            try
            {
                entity.AddToservico(pservico);
                entity.SaveChanges();
            }
            catch (Exception ex)
            {
                agilesaudeContext.removeInstance();
                throw ex;
            }
        }

        public void Update()
        {
            try
            {
                entity.SaveChanges();
            }
            catch (Exception ex)
            {
                agilesaudeContext.removeInstance();
                throw ex;
            }
        }

    }
}
